package com.hzhc.util;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.codec.binary.Base64;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;

/**
 * @author wuxiaoke
 * @description TODO
 * @date 2024/1/31 08:47
 */
public class EncryptAndDecrypt {

    public static final String KEY = "U0Xg55zo9-TglUjxvBG_Dac_2NAsAyQc";
    public static String decrypt(String encryptStr, String decryptKey) throws Exception {
        KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
        keyGenerator.init(128);
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(),"AES"));
        byte[] encryptBytes = Base64.decodeBase64(encryptStr);
        byte[] decryptBytes = cipher.doFinal(encryptBytes);
        return new String(decryptBytes, StandardCharsets.UTF_8);
    }

    public static void main(String[] args) throws Exception {
//        String userInfoStr = "Py0Hz54GLZT6EyRb1hmOXguLnv6r9vYHpOialJ2ErtARIynKWOii+VR8t3w/PrlXcGAg3Q22mBVw626/q4TCBfJi4FwPLVeXldTvIRUIZ9ipBnSSUAg9KMU/hNEEv+A0F3bKSrcIBVu6oHzDwX88yi85L7VnBiraj9TdOs3zoVVXAirduEAcqa7Z8dDKJI8hOBjzEx01lCacx2WELfwDspxqcswDVFH80LwFrLYSPTaxb6cdC6zDUHqNs+1d7U9t2pBJ+6xVC3pGEekthXDLX9NR91fFDMwBllviSHQzQyZ/8qIqd2L0FySoEnVkB2oN9rBHuBcIGtYgeW9wQX4Imbbor7qcc1o/4HRnk+m/Tsie3gEvzkZKqihBgIMNF/4wkPjc4NxC8lYx99pNiyGOxQFO9GaQdSOAEL+MMQAbBrKndW9yb0CRXRlazB98Z/z3ZLwrL7Od0DJht17nuNb7ZHv/KnlaHMF/80TjTzyM77jV8+rb1mCBboVRR+P0GdiFjUCEdvm7i50XZzYQ96PrN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foStr, EncryptAndDecrypt.KEY);
        JSONObject userInfoJson =  JSON.parseObject(decryptStr);
        System.out.println("解密userInfoStr====="+userInfoJson);
    }
}
